//
//  TopicCommentTableViewCell.m
//  news
//
//  Created by Qiaobuyong on 16/3/11.
//  Copyright © 2016年 imacbookair. All rights reserved.
//

#import "TopicCommentTableViewCell.h"
// 宏定义
#define KWITH [UIScreen mainScreen].bounds.size.width /375
#define KHIGHT [UIScreen mainScreen].bounds.size.height /667
@implementation TopicCommentTableViewCell
#pragma mark - 初始化

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 背景
        self.background = [[UIImageView alloc] init];
        _background.image = [UIImage imageNamed:@"bg"];
        [self.contentView addSubview:_background];

        
        // 用户头像
        self.userHeadImage = [[UIImageView alloc] init];
        //        _userTou.backgroundColor = [UIColor redColor];
        [self.background addSubview:_userHeadImage];

        
        // userName
        self.userName = [[UILabel alloc] init];
        _userName.font = [UIFont systemFontOfSize:12];
        //        _userMing.backgroundColor = [UIColor blueColor];
        [self.background addSubview:_userName];

        
        // question
        self.question = [[UILabel alloc] init];
        _question.numberOfLines = 0;
        _question.font = [UIFont systemFontOfSize:14];
        //        _question.backgroundColor = [UIColor purpleColor];
        [self.background addSubview:_question];

        
        // zhong
        self.line = [[UILabel alloc] init];
        //        _zhong.backgroundColor = [UIColor redColor];
        _line.text = @"........................................................................";
        _line.textColor = [UIColor redColor];
        [self.background addSubview:_line];

        
        // tou
        self.headImage = [[UIImageView alloc] init];
        //        _tou.backgroundColor = [UIColor grayColor];
        [self.background addSubview:_headImage];

        
        // name
        self.name = [[UILabel alloc] init];
        _name.font = [UIFont systemFontOfSize:12];
        //        _name.backgroundColor = [UIColor magentaColor];
        [self.background addSubview:_name];

        
        // answer
        self.answer = [[UILabel alloc] init];
        _answer.numberOfLines = 0;
        _answer.font = [UIFont systemFontOfSize:14];
        //        _answer.backgroundColor = [UIColor greenColor];
        [self.background addSubview:_answer];

        
        //
        self.lines = [[UIView alloc] init];
        _lines.backgroundColor = [UIColor blackColor];
        _lines.alpha = 0.4;
        [self.background addSubview:_lines];

        
        // time
        self.time = [[UILabel alloc] init];
        //        _time.backgroundColor = [UIColor purpleColor];
        [self.background addSubview:_time];

        
        // ping
        self.commentImage = [[UIImageView alloc] init];
        //        _ping.backgroundColor = [UIColor blueColor];
        [self.background addSubview:_commentImage];
        
        // pinglun
        self.commentCount = [[UILabel alloc] init];
        //        _pinglun.backgroundColor = [UIColor redColor];
        [self.background addSubview:_commentCount];

        
        // zan
        self.praiseImage = [[UIImageView alloc] init];
        //        _zan.backgroundColor = [UIColor greenColor];
        [self.background addSubview:_praiseImage];

        
        // support
        self.praiseCount = [[UILabel alloc] init];
        //        _support.backgroundColor = [UIColor purpleColor];
        [self.background addSubview:_praiseCount];

        
    }
    return  self;
}
#pragma mark - 自适应高度的计算
+ (CGFloat)heightWihtText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:18]};
    CGSize s = CGSizeMake((375 - 20) * KWITH, 400 * KHIGHT);
    CGRect h = [text boundingRectWithSize:s options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return h.size.height;
}

#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    _userHeadImage.frame = CGRectMake(10 * KWITH ,10 * KHIGHT, 30 * KWITH, 30 * KHIGHT);
    _userName.frame      = CGRectMake(50 * KWITH, 10 * KHIGHT, 300 * KWITH, 20 * KHIGHT);
    CGFloat h            = [[self class] heightWihtText:_question.text];
    _question.frame      = CGRectMake(50 * KWITH, 30 * KHIGHT, self.contentView.frame.size.width - 90, h);
    _line.frame          = CGRectMake(40 * KWITH, 40 * KHIGHT + h, self.contentView.frame.size.width - 80, 10 * KHIGHT);
    _headImage.frame     = CGRectMake(10 * KWITH ,60 * KHIGHT + h, 30 * KWITH, 30 * KHIGHT);
    _name.frame          = CGRectMake(50 * KWITH, 60 * KHIGHT + h, 300 * KWITH, 20 * KHIGHT);
    CGFloat r            = [[self class] heightWihtText:_answer.text];
    _answer.frame        = CGRectMake(50 * KWITH, 80 * KHIGHT + h, self.contentView.frame.size.width - 90, r);
    _lines.frame         = CGRectMake(20 * KWITH, 90 * KHIGHT + h + r, self.contentView.frame.size.width - 60, 1);
    _time.frame          = CGRectMake(50 * KWITH, 100 * KHIGHT + h + r, 80 * KWITH, 20 * KHIGHT);
    _commentImage.frame  = CGRectMake(260 * KWITH, 100 * KHIGHT + h + r, 20 * KWITH, 20 * KHIGHT);
    _commentCount.frame  = CGRectMake(280 * KWITH, 100 * KHIGHT + h + r, 30 * KWITH, 20 * KHIGHT);
    _praiseImage.frame   = CGRectMake(300 * KWITH, 100 * KHIGHT + h + r, 20 * KWITH, 20 * KHIGHT);
    _praiseCount.frame   = CGRectMake(320 * KWITH, 100  * KHIGHT + h + r, 30 * KWITH, 20 * KHIGHT);
    _background.frame    = CGRectMake(10 * KWITH, 10 * KHIGHT, self.contentView.frame.size.width - 20, h + r + 140 * KHIGHT);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
